<?php
include "../conn.php";
include "s-cookie.php";
$StudentId = $_SESSION['s-id'];
?>

<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>选课界面</title>
    <link rel="stylesheet" type="text/css" href="../css/htmleaf-demo.css">
    <link rel="stylesheet" type="text/css" href="../css/nav.css">
    <link rel="stylesheet" type="text/css" href="../fonts/iconfont.css">

    <link rel="stylesheet" href="../css/bootstrap-theme.css"/>

    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <link rel="stylesheet" href="../css/bootstrap-theme.min.css"/>
    <link rel="stylesheet" href="../css/bootstrap.css"/>
    <script type="text/javascript" src="../js/bootstrap3.0.3.min.js"></script>
    <script type="text/javascript"></script>
    <script>
        function choose(teacherid) {
            var id = teacherid;
            window.location.href = "unactivate.php?teacherid=" + id;
        }
    </script>
    <link rel="stylesheet" type="text/css" href="../css/style.css">

    <style>

    </style>

</head>

<body class="bodycolor">

<nav class="navbar navbar-default navbar-fixed-top" style="clear: left;">
    <div class="container">
        <div class="navbar-right navfont" id="navbar-collapse">
            <p>华软网络技术系毕业管理系统</p>
        </div>
        <a href="s-cookie.php?cookie=out" id="out">退出</a>
    </div>

</nav>

<div class="nav topx navbackground-s" id="nav">
    <div>

        <div style="border-bottom:1px solid rgba(255,255,255,.1)"><img src="../images/mini.png"></div>
    </div>
    <ul>
        <li class="nav-item">
            <a href="s-index.php"><i class="my-icon nav-icon icon_2"></i><span>首页</span><i class="my-icon nav-more"></i></a>

        </li>
        <li class="nav-item">
            <a href="s-mykt.php"><i class="my-icon nav-icon icon_1"></i><span>我的课题</span><i
                    class="my-icon nav-more"></i></a>
        </li>

        <li class="nav-item">
            <a href="s-examination.php"><i class="my-icon nav-icon icon_3"></i><span>成绩考核表</span><i
                    class="my-icon nav-more"></i></a>

        </li>
        <li class="nav-item">
            <a href="s-information.php"><i class="my-icon nav-icon icon_4"></i><span>我的资料</span><i
                    class="my-icon nav-more"></i></a>
        </li>
        <li class="nav-item">
            <a href="teachresearch.php"><i class="my-icon nav-icon icon_6"></i><span>选课</span><i
                    class="my-icon nav-more"></i></a>
        </li>
    </ul>
</div>

<div class="indexborder ">

    <div class="bannerdiv" style="margin-top: 70px">
        <!--colspan="2"-->

        <div class="box-inline indexdiv2 panel panel-default auto" align="center">
            <div class="panel panel-primary panel-success">
                <div class="panel-heading" style="padding: 0px;color: black;font-style:initial;">
                    <h3 class="panel-title " style="background-color: #536d90;padding: 15px;">教师选择</h3>
                </div>
                <div class="panel-body">
                    <table class="table  table-hover  table-striped">
                        <?
                        $direction = $_GET["direction"];
                        $sql = "select * from teacher where CurrSubject='$direction'";
                        $result = mysqli_query($conn, $sql);
                        ?><tr class="thcolor">
                                <th>教师名</th>
                                <th>性别</th>
                                <th>电话</th>
                                <th>邮箱</th>
                                <th>QQ</th>
                                <th>简介</th>
                                <th>选课</th>
                            </tr><?
                        while ($row = mysqli_fetch_array($result)) {
                            ?>

                            <tr>
                                <td data-label="教师名"><?= $row[2] ?></td>
                                <td data-label="性别"><?= $row[3] ?></td>
                                <td data-label="电话"><?= $row[6] ?></td>
                                <td data-label="邮箱"><?= $row[7] ?></td>
                                <td data-label="QQ"><?= $row[8] ?></td>
                                <td data-label="简介"><?= $row[9] ?></td>
                                <td data-label="选课"><input type="button" name="selectsub" value="选择" onclick="choose(<?= $row[0] ?>)">
                                </td>
                            </tr>
                        <? } ?>

                    </table>
                    <div class="panel-heading" style="padding: 0px;color: black;font-style:initial;">
                        <h3 class="panel-title " style="background-color: #536d90;padding: 15px;">选课状态</h3>
                    </div>

                    <?
                    $checksubsql = "select * from  project where Student_StudentId=$StudentId";
                    $checksubresult = $conn->query($checksubsql);
                    $checkchoosql = "select state,StudentId from  choosesubject WHERE StudentId=$StudentId";
                    $checkchooresult = $conn->query($checkchoosql);
                    $checkproject="select activate from project WHERE Student_StudentId=$StudentId";
                    $checkprojectresult=$conn->query($checkproject);
                    $checkprojectrow=$checkprojectresult->fetch_array();
                    $checkchoorow = $checkchooresult->fetch_array();
                    $checkselfsql = "select activite from probyself WHERE StudentId=$StudentId";
                    $checkselfresult = $conn->query($checkselfsql);
                    $checkselrow = $checkselfresult->fetch_array();
                    $checkprojectresult=$conn->query($checkproject);
                    $checkprojectrow=$checkprojectresult->fetch_array();
                    $checkproject="select activate from project WHERE Student_StudentId=$StudentId";
                    $checkprojectresult=$conn->query($checkproject);
                    $checkprojectrow=$checkprojectresult->fetch_array();
                    if ($checkchooresult->num_rows != 0) {
                        if ($checkchoorow[0] == 0) {
                            $row = $checksubresult->fetch_array(); ?>

                            <h2>正在选课</h2>
                            <?
                            $sql = "select ProjectName,Category,ProjectOrigin,Summary,StudentId from project as p JOIN choosesubject as ch on p.ProjectId=ch.ProjectId WHERE ch.StudentId=$StudentId";
                            $result = $conn->query($sql);
                            while ($row = $result->fetch_array()) {
                                ?>
                                <table class="table  table-hover  table-striped">
                                    <tr class="thcolor">
                                        <th>课题名</th>
                                        <th>类别</th>
                                        <th>来源</th>
                                        <th>概述</th>
                                        <th>操作</th>
                                    </tr>
                                    <tr>
                                        <td data-label="课题名"><?= $row[0] ?></td>
                                        <td data-label="类别"><?= $row[1] ?></td>
                                        <td data-label="来源"><?= $row[2] ?></td>
                                        <td data-label="概述"><?= $row[3] ?></td>
                                        <td data-label="操作"><input type="button" value="删除选课"
                                                   onclick="deletetask('deletepro',<?= $row[4] ?>)">
                                        </td>
                                    </tr>
                                </table>
                            <?
                            }
                        } elseif ($checkchoorow[0] == 1) {
                            ?>
                            <h2>你已成功选题，请到我的课题界面查看</h2>
                        <?
                        } elseif ($checkchoorow[0] == 2) {
                            ?>
                            <h2>该教师已选他人，请重新选题</h2>
                            <input type="button" value="重新选题" onclick="deletetask('reset',<?= $checkchoorow[1] ?>)">
                        <?
                        }

                    } else if ($checkselfresult->num_rows > 0) {
                        if ($checkselrow[0] == 0) {
                            ?>
                            <h2>正在自拟</h2>
                            <? $sql = "select ProjectName,Category,ProjectOrigin,Summary,ProjectId from probyself where StudentId=$StudentId";
                            $result = $conn->query($sql);
                            while ($row = $result->fetch_array()) {
                                ?>
                                <table class="table  table-hover  table-striped">
                                    <tr class="thcolor">
                                        <th>课题名</th>
                                        <th>类别</th>
                                        <th>来源</th>
                                        <th>概述</th>
                                        <th>操作</th>
                                    </tr>
                                    <tr>
                                        <td data-label="课题名"><?= $row[0] ?></td>
                                        <td data-label="类别"><?= $row[1] ?></td>
                                        <td data-label="来源"><?= $row[2] ?></td>
                                        <td data-label="概述"><?= $row[3] ?></td>
                                        <td data-label="操作"><input type="button" value="删除自拟"
                                                                   onclick="deletetask('deletedself',<?= $row[4] ?>)">
                                        </td>
                                    </tr>
                                </table>
                            <? }
                        } elseif ($checkselrow[0] == 1) {
                            ?>
                            <h2>你已成功选题，请到我的课题界面查看</h2>
                        <?
                        }
                    }else if($checkprojectrow[0]==1){
                        ?>
                        <h2>你已成功选题，请到我的课题界面查看</h2>
                    <?

                    } else { ?>
                        <h2>还未选课</h2>
                        <input type="button" value="自拟课题" onclick="chooseself()">
                    <?
                    }
                    ?>

                    <button><a onclick="javascript:history.go(-1);">返回</button>
                </div>

            </div>


        </div>
    </div>
</div>


<script>
    window.jQuery || document.write('<script src="../js/jquery-1.11.0.min.js"><\/script>')
</script>
<script type="text/javascript" src="../js/nav.js"></script>
<script type="text/javascript" src="../js/jquery-1.11.0.min.js"></script>
<script>
    function chooseself() {
        window.location.href = "s-subjectNew.html";
    }
    function deletetask(method, id) {

        $.ajax({
            type: "POST",
            url: "chooseTask.php",
            data: "method=" + method + "&Id=" + id,
            success: function (msg) {
                alert("提示: " + msg);
                window.location.href = "teachresearch.php";
            }
        });
    }
</script>

</body>

</html>














